﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using AMStudio.Windows.Forms;
using AMStudio.Common;

namespace AMStudio.UserInterface
{
    public partial class StationUI02 : StationUI
    {
        public StationUI02()
        {
            this.UIName = "StationUI02";
            this.StationIndex = 2;
            InitializeComponent();
        }
        public override bool ActivateUI()
        {
            bool result = base.ActivateUI();

            if (WorkorderDB.ActiveProduct != null)
            {
                this.txtProductName.Text = WorkorderDB.ActiveProduct.Name.ToString();
                this.txtProgramNO.Text = WorkorderDB.ActiveProduct.St2ProgramID.ToString();
                this.txtToolingID.Text = WorkorderDB.ActiveProduct.St2ToolingID.ToString();
                this.txtRequiredJob.Value = int.Parse(WorkorderDB.ActiveProduct.St2ProgramID.ToString());
            }

            return result;
        }


        private void StationUI02_Load(object sender, EventArgs e)
        {
            base.SubscribeEvent("MANAGER_RET");
        }

        protected override void UIDB_RfreshTag(Common.UserInterfaceItem item)
        {
            base.UIDB_RfreshTag(item);
            if (item.RelatedControl.Name.StartsWith("DWORD"))
            {
                string[] res = item.value.ToString().Split(';');
                if (res.Length >= 2)
                {
                    decimal value = (decimal)(int.Parse(res[1]) * 65536 + int.Parse(res[0])) / (decimal)100;
                    item.RelatedControl.Text = value.ToString();
                }
                return;
            }
            if (item.RelatedControl is TextBox)
            {
                item.RelatedControl.Text = item.value.ToString();
            }
        }
        protected override void SetUserPrivilige(object sender, EventArgs e)
        {
            User current = UserDB.CurrentLoginUser;
            base.SetUserPrivilige(sender, e);
            //Control[] findCtl = null;
            switch (current.AuthorizationSet)
            {
                case 0:
                    this.tabItemMaintenace.Visible = true;
                    this.tabItemConfiguration.Visible = true;
                    this.tabItemRFTag.Visible = true;
                    this.tabItemIput.Visible = true;
                    this.tabItemOutput.Visible = true;
                    break;
                case 1:
                    this.tabItemMaintenace.Visible = true;
                    this.tabItemConfiguration.Visible = false;
                    this.tabItemRFTag.Visible = false;
                    this.tabItemIput.Visible = false;
                    this.tabItemOutput.Visible = false;
                    break;
                case 2:
                default:
                    this.tabItemMaintenace.Visible = false;
                    this.tabItemConfiguration.Visible = false;
                    this.tabItemRFTag.Visible = false;
                    this.tabItemIput.Visible = false;
                    this.tabItemOutput.Visible = false;
                    break;
            }
        }

        private void labelX2_Click(object sender, EventArgs e)
        {

        }

        private void simpleEllipse5_Load(object sender, EventArgs e)
        {

        }

        private void labelX141_Click(object sender, EventArgs e)
        {

        }

        private void labelX33_Click(object sender, EventArgs e)
        {

        }
        protected override void Language_RfreshTag(LanguageItem item)
        {
            base.Language_RfreshTag(item);


            if ((item != null) && (item.Language[LanguageString] != null))
            {
                if (item.ControlName == "tabStrip1")
                {

                    string[] titles = item.Language[LanguageString].ToString().Split(new string[] { "||" }, StringSplitOptions.None);

                    if (titles.Length >= 6)
                    {
                        this.tabItemStatus.Text = titles[0];
                        this.tabItemIput.Text = titles[1];
                        this.tabItemOutput.Text = titles[2];
                        this.tabItemMaintenace.Text = titles[3];
                        this.tabItemConfiguration.Text = titles[4];
                        this.tabItemRFTag.Text = titles[5];

                    }
                }
            }
        }
        protected override void Language_InitializeControl(Control UIControl)
        {
            base.Language_InitializeControl(UIControl);

            if (UIControl is StationUI)
            {
                LanguageItem item = LanguageDB.UIDBTags[this.UIName + ".tabStrip1"] as LanguageItem;
                if ((item != null) && (item.Language[LanguageString] != null))
                {
                    string[] titles = item.Language[LanguageString].ToString().Split(new string[] { "||" }, StringSplitOptions.None);

                    if (titles.Length >= 6)
                    {
                        this.tabItemStatus.Text = titles[0];
                        this.tabItemIput.Text = titles[1];
                        this.tabItemOutput.Text = titles[2];
                        this.tabItemMaintenace.Text = titles[3];
                        this.tabItemConfiguration.Text = titles[4];
                        this.tabItemRFTag.Text = titles[5];
                    }
                }
            }


        }
    }
}

